/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.data.Sequence;


/**
 *
 * @author Daniel Quest
 * @date   Jan 11 2009
 */
public class Protein extends BioSequence {
    public Protein(){
        super.init();
    }
    public Protein(String s){
        set(s);
        super.init();
    }

/**
For those programs that use amino acid query sequences (BLASTP and TBLASTN), the accepted amino acid codes are:

    A  alanine                         P  proline
    B  aspartate or asparagine         Q  glutamine
    C  cystine                         R  arginine
    D  aspartate                       S  serine
    E  glutamate                       T  threonine
    F  phenylalanine                   U  selenocysteine
    G  glycine                         V  valine
    H  histidine                       W  tryptophan
    I  isoleucine                      Y  tyrosine
    K  lysine                          Z  glutamate or glutamine
    L  leucine                         X  any
    M  methionine                      *  translation stop
    N  asparagine                      -  gap of indeterminate length
*/

    public boolean valid(String s){
        if(s.matches("[ABCDEFGHIKLMNPQRSTUVWYZX\\-\\*\"]+"))
            return true;
        if(s.matches("[abcdefghiklmnpqrstuvwyzx\\-\\*\"]+"))
            return true;
        if(s.matches("/translation=\"[ABCDEFGHIKLMNPQRSTUVWYZXabcdefghiklmnpqrstuvwyzx\\-\\*\"]+\"?"))
            return true;
        return false;
    }

    public String convertLine(String line){
        String c = line;
        int i = 0;
        c = c.trim();
        String tr = "/translation=";
        if( c.startsWith(tr) ){
            i = c.indexOf(tr);
            //System.err.println(i);
            c = c.substring( i+tr.length() );
        }
        if( c.startsWith("\"") ){
            c = c.substring(1);
            //System.err.println("c~" + c);
        }
        if( c.endsWith("\"")){
            c = c.substring(0, c.length() -1 );
            //System.err.println("c~" + c);
        }
        if( c.matches("[abcdefghiklmnpqrstuvwyzx\\-\\*\"]+") ){
            c = c.toUpperCase();
        }
        if( c.matches("[^ABCDEFGHIKLMNPQRSTUVWYZX\\-\\*\"]+") ){
            c = "";
        }
        return c;
    }

    public String convertMultiLine(String[] lines){
        String s ="";
        for(int i=0; i<lines.length; i++){
            String line = convertLine(lines[i]);
            s = s + line;
        }
        return s;
    }

}
